<template>
 <div>
    <button @click="isShow = true">点我弹个窗</button>
    <teleport to="body">
    <!-- <teleport to="#box"> -->
      <!-- <div id="box"></div> 写在index.html中 -->
      <div class="mask" v-if="isShow">
        <div class="dialog">
          <h3>我是一个弹框</h3>
          <button @click="isShow = false">关闭弹框</button>
        </div>
      </div>
    </teleport>
 </div>
</template>

<script>
import { ref } from 'vue'
export default {
  name: 'Dialog',
  setup(props) {
    let isShow = ref(false)
    return {
      isShow
    }
  }
}
</script>

<style scoped>
.mask {
  position: absolute;
  top: 0;bottom: 0;left: 0;right: 0;
  background-color: rgba(0, 0, 0, .5)
}
.dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  width: 300px;
  height: 300px;
  text-align: center;
  background-color: green;
}
</style>  